package com.helwen.tools.zhijiang;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/***
*从excel中读取数据。
*
 * @param null
*@author:Dell
*@date:2021/6/27 16:10
*@return:
 * @return null
*/
public class PoiRead {

    public static void main(String[] args) {
//获取文件
        File file=new File("D:\\poi_1119.xls");
//文件输入流
        try {
            FileInputStream stream=new FileInputStream(file);
//工作薄
            HSSFWorkbook workbook=new HSSFWorkbook(stream);
//Sheet
//HSSFSheet sheet=workbook.getSheet("sheet0");
            HSSFSheet sheet=workbook.getSheetAt(0);
//
            int firstRowNumber=0;
            int lastRowNumber=sheet.getLastRowNum();
            for(int i=firstRowNumber;i<lastRowNumber;i++){
                HSSFRow row=sheet.getRow(i);
                int firstCellNumber=0;
                int lastCellNumber=row.getLastCellNum();
//
                for(int j=firstCellNumber;j<lastCellNumber;j++){
                    HSSFCell cell=row.getCell(j);
                    String value=cell.getStringCellValue();
                    System.out.print(value+"\t");
                }
                System.out.println("");
            }
        } catch (IOException e) {
// TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
